/*
1.use C++ to show the function "matrix_calc_taskA".
and the input parameter is "TaskMatrixInfoA**",which is the same as Guidance.
*/
#include <iostream>
using namespace std;

typedef struct {
	int* 			rowArray;
	const int* 		rowOffset;
	int 			rowArraySize;
	const int* 		columnIndice;
	const double* 	S;
	const double*	valueNormalMatrix;
	double* 		Id;
}TaskMatrixInfoA;

void matrix_calc_taskA(TaskMatrixInfoA** listDataList,int N)
{
	for (int it = 0; it < N;++it){
		const int node = (*listDataList)->rowArray[it];
		for (int j = (*listDataList)->rowOffset[node];j < (*listDataList)->rowOffset[node + 1];++j){
			(*listDataList)->Id[node] +=(*listDataList)->valueNormalMatrix[j]* (*listDataList)->S[(*listDataList)->columnIndice[j]];
		}
	}
}

int main()
{
	TaskMatrixInfoA** listData;
	TaskMatrixInfoA* listData_temp=new TaskMatrixInfoA;
	listData = &listData_temp;
	(*listData)->rowArraySize = 4;
	int rowArray_[4]={0,1,2,3};
	(*listData)->rowArray=rowArray_;
	int rowOffset_[5] = {0,2,4,7,9};
	(*listData)->rowOffset=rowOffset_;
	int columnIndice_[9] = {0,1,1,2,0,2,3,0,3};
	(*listData)->columnIndice=columnIndice_;
	double S_[4]={3.5,2.5,4.5,1.5};
	(*listData)->S=S_;
	double valueNormalMatrix_[9]={1,5,8,3,5,2,4,9,1};
	(*listData)->valueNormalMatrix=valueNormalMatrix_;
	double Id_[4]={0};
	(*listData)->Id=Id_;
	
//	cout<< (*listData)->rowArraySize; 

	for(int i=0;i<4;++i){
		cout << (*listData)->Id[i] <<" ";
	}
	cout<<"\n";
	matrix_calc_taskA(listData , 4);
	for(int i=0;i<4;++i){
		cout << (*listData)->Id[i] <<" ";
	}
	
	delete(listData_temp);
  	return 0;
}

